package main

import "sort"

func FindSliceStrDiff(sliceSrc, sliceDest []string) ([]string, []string) {
	var sIndex []int
	var isFind bool
	var newSlice []string

	copySliceDest := make([]string, len(sliceDest))
	// 拷贝一份，不然会影响原来的内容
	copy(copySliceDest, sliceDest)
	for i := range sliceSrc {
		for j := range copySliceDest {
			if sliceSrc[i] == copySliceDest[j] {
				isFind = true
				copySliceDest = append(copySliceDest[:j], copySliceDest[j+1:]...)
				break
			}
		}
		if !isFind {
			sIndex = append(sIndex, i)
		}
		isFind = false
	}
	for i := range sIndex {
		newSlice = append(newSlice, sliceSrc[sIndex[i]])
	}
	return copySliceDest, newSlice
}

func CompareSlice(sliceSrc, sliceDest []string) bool {
	if len(sliceSrc) != len(sliceDest) {
		return false
	}
	sort.Sort(sort.Reverse(sort.StringSlice(sliceSrc)))
	sort.Sort(sort.Reverse(sort.StringSlice(sliceDest)))
	for i := range sliceSrc {
		if sliceSrc[i] != sliceDest[i] {
			return false
		}
	}
	//for i := range sliceSrc {
	//	for j := range sliceDest {
	//		if sliceSrc[i] != sliceDest[j] {
	//			return true
	//		}
	//	}
	//}
	return true
}

func GetMultipleSliceLen(missExpr, moreExpr []string) int {
	return len(missExpr) + len(moreExpr)

}

func RemoveDuplicateElement(strSlice []string) []string {
	result := make([]string, 0, len(strSlice))
	temp := map[string]struct{}{}
	for _, item := range strSlice {
		if _, ok := temp[item]; !ok {
			temp[item] = struct{}{}
			result = append(result, item)
		}
	}
	return result
}
